package com.permission.model;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.solution.framework.model.BaseBean;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * Created with generator tools.
 * User: sunguangzhu
 * DateTime:2014-05-07 01:19:05
 */
@Entity
@Table(name = "t_per_resource")
public class PerResource extends BaseBean implements java.io.Serializable {
    /**
     * 名称
     */
    private java.lang.String name;

    /**
     * 菜单文本
     */
    private java.lang.String menuText;

    /**
     * 菜单类型
     */
    private java.lang.Integer type;

    /**
     * 地址
     */
    private java.lang.String url;

    /**
     * 上级资源
     */
    private com.permission.model.PerResource parent;



    private String code;

    /**
     * 角色资源集合
     */
    private java.util.Set<com.permission.model.PerRoleResource> perRoleResources;

    /**
     * default constructor
     */
    public PerResource() {
    }

    /**
     * full constructor
     *
     * @param name
     * @param menuText
     * @param type
     * @param url
     * @param parent
     * @param perRoleResources
     */
    public PerResource(java.lang.String name, java.lang.String menuText, java.lang.Integer type, java.lang.String url, com.permission.model.PerResource parent, java.util.Set<com.permission.model.PerRoleResource> perRoleResources) {
        this.name = name;
        this.menuText = menuText;
        this.type = type;
        this.url = url;
        this.parent = parent;
        this.perRoleResources = perRoleResources;
    }

    /**
     * getter
     */
    @Column
    public java.lang.String getName() {
        return this.name;
    }

    /**
     * setter
     *
     * @param name
     */
    public void setName(java.lang.String name) {
        this.name = name;
    }

    /**
     * getter
     */
    @Column
    public java.lang.String getMenuText() {
        return this.menuText;
    }

    /**
     * setter
     *
     * @param menuText
     */
    public void setMenuText(java.lang.String menuText) {
        this.menuText = menuText;
    }

    /**
     * getter
     */
    @Column
    public java.lang.Integer getType() {
        return this.type;
    }

    /**
     * setter
     *
     * @param type
     */
    public void setType(java.lang.Integer type) {
        this.type = type;
    }

    /**
     * getter
     */
    @Column
    public java.lang.String getUrl() {
        return this.url;
    }

    /**
     * setter
     *
     * @param url
     */
    public void setUrl(java.lang.String url) {
        this.url = url;
    }

    @Column
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    /**
     * getter
     */
    @JsonManagedReference
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "parent_id")
    @NotFound(action = NotFoundAction.IGNORE)
    @ForeignKey(name = "fk_perresource_parent")
    public com.permission.model.PerResource getParent() {
        return this.parent;
    }

    /**
     * setter
     *
     * @param parent
     */
    public void setParent(com.permission.model.PerResource parent) {
        this.parent = parent;
    }

    /**
     * getter
     */
    @JsonBackReference
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "perResource")
    public java.util.Set<com.permission.model.PerRoleResource> getPerRoleResources() {
        return this.perRoleResources;
    }

    /**
     * setter
     *
     * @param perRoleResources
     */
    public void setPerRoleResources(java.util.Set<com.permission.model.PerRoleResource> perRoleResources) {
        this.perRoleResources = perRoleResources;
    }

}
